﻿using System;
using System.Text;
using System.Configuration;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Collections.Generic;
using BLLBusiness.HeRegistryDatalayer;
using System.Drawing;
using System.IO;
using System.Collections.ObjectModel;

namespace BLLBusiness
{
    public class cBLLService : IBLLService
    {

        #region Permission Module

        public int RegisterUser(RegistrationModel RegistrationModel)
        {
            int Status = 0;


            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new HeRegistryDatalayer.IeCashDatalayerClient();
            try
            {
                //1 = User with that Username Already Exists
                //2= There was an Error 
                //0= Successfully Registered
                //3 = Email Already Exists
                if (CheckUserExistance(RegistrationModel.sUsername) == 0)
                {
                    if (CheckEmailExistance(RegistrationModel.sEmail) == 0)
                    {
                        objeCash.RegisterUser(RegistrationModel);

                        SendEmail(RegistrationModel.sFirstName, RegistrationModel.sEmail, RegistrationModel.sGUIDR);

                        Status = 0;
                    }
                    else
                    {
                        Status = 3;
                    }
                }
                else
                {
                    Status = 1;
                }
            }
            catch (Exception ex)
            {
                Status = 2;
                throw ex;
            }
            finally
            {
                objeCash.Close();
            }
            return Status;

        }

        public int RegisterUserTuckShop(TuckShopRegistrationModel TuckShoRegistrationModel)
        {
            int Status = 0;

            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new HeRegistryDatalayer.IeCashDatalayerClient();
            try
            {
                //1 = User with that Username Already Exists
                //2= There was an Error 
                //0= Successfully Registered
                //3 = Email Already Exists
                if (CheckUserExistance(TuckShoRegistrationModel.sUsername) == 0)
                {
                    if (CheckEmailExistance(TuckShoRegistrationModel.sEmail) == 0)
                    {
                        objeCash.RegisterUserTuckShop(TuckShoRegistrationModel);

                        SendEmail(TuckShoRegistrationModel.sUsername, TuckShoRegistrationModel.sEmail, TuckShoRegistrationModel.sGUIDR);

                        Status = 0;
                    }
                    else
                    {
                        Status = 3;
                    }
                }
                else
                {
                    Status = 1;
                }
            }
            catch (Exception ex)
            {
                Status = 2;
                throw ex;
            }
            finally
            {
                objeCash.Close();
            }
            return Status;

        }

        /// <summary>
        /// Convert a Blob to Image
        /// </summary>
        /// <param name="byteArrayIn"></param>
        /// <returns></returns>
        private Image byteArrayToImage(byte[] byteArrayIn)
        {
            // Write the byte array <strong class="highlight">to</strong> the memory stream
            MemoryStream ms = new MemoryStream(byteArrayIn);

            // Create a new bitmap object from the memory stream
            Bitmap bmp = new Bitmap(ms);

            // Finally, return the bitmap
            return bmp;
        }
        public int ConfirmRegistration(string sGUID)
        {
            int msIsValid = 0;

            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new HeRegistryDatalayer.IeCashDatalayerClient();
            try
            {
                msIsValid = objeCash.ConfirmRegistration(sGUID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objeCash = null;
            }
            return msIsValid;
        }

        private int CheckUserExistance(String sUSERNAME)
        {
            int m_Exists = 0;

            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new HeRegistryDatalayer.IeCashDatalayerClient();

            try
            {
                m_Exists = objeCash.CheckUserExistance(sUSERNAME);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                objeCash = null;
            }
            return m_Exists;
        }


        private int CheckEmailExistance(String sEmail)
        {
            int m_Exists = 0;

            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new HeRegistryDatalayer.IeCashDatalayerClient();

            try
            {
                m_Exists = objeCash.CheckEmailExistance(sEmail);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                objeCash = null;
            }
            return m_Exists;
        }

        public void SendEmail(String ClientName, String ClientEmail, string GUID)
        {
            String FromE = ConfigurationManager.AppSettings.Get("FromE");

            String To_1 = ClientEmail;

            String Gmail_Password = ConfigurationManager.AppSettings.Get("Gmail_Password");

            String Networked_Username = ConfigurationManager.AppSettings.Get("Networked_Username");

            int Gmailport = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Gmailport"));

            String Server_Host = Convert.ToString(ConfigurationManager.AppSettings.Get("GmailHost"));

            try
            {
                MailMessage mm = new MailMessage();

                SmtpClient smtp = new SmtpClient();

                mm.From = new MailAddress(FromE);

                //add the Emails to a To Collection

                mm.To.Add(new MailAddress(To_1));

                mm.Subject = "Ecash Account Registration";

                mm.Body = BuildBody(ClientName, GUID);

                mm.IsBodyHtml = true;

                smtp.Host = Server_Host;

                smtp.EnableSsl = true;

                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

                NetworkCred.UserName = Networked_Username;

                NetworkCred.Password = Gmail_Password;

                smtp.UseDefaultCredentials = true;

                smtp.Credentials = NetworkCred;

                smtp.Port = Gmailport;

                smtp.Send(mm);
            }
            catch (System.Net.Mail.SmtpException)
            {
                throw;
            }
        }


        public UserModel AuthonticateUser(String sUsername, String sPassword)
        {

            UserModel model = new UserModel();

            try
            {
                HeRegistryDatalayer.IeCashDatalayerClient Datalayer = new IeCashDatalayerClient();

                model = Datalayer.AuthonticateUser(sUsername, sPassword);

            }
            catch (Exception)
            {


            }
            finally
            {

            }
            return model;
        }





        public void SendEmail(String ClientName, String Password, String ClientEmail, String Message, String Subject)
        {
            String FromE = ConfigurationManager.AppSettings.Get("FromE");

            String To_1 = ClientEmail;

            String Gmail_Password = ConfigurationManager.AppSettings.Get("Gmail_Password");

            String Networked_Username = ConfigurationManager.AppSettings.Get("Networked_Username");

            int Gmailport = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Gmailport"));

            String Server_Host = Convert.ToString(ConfigurationManager.AppSettings.Get("GmailHost"));

            try
            {
                MailMessage mm = new MailMessage();

                SmtpClient smtp = new SmtpClient();

                mm.From = new MailAddress(FromE);

                //add the Emails to a To Collection

                mm.To.Add(new MailAddress(To_1));

                mm.Subject = Subject;

                mm.Body = BuildBody_Recover(ClientName, Password, Message);

                mm.IsBodyHtml = true;

                smtp.Host = Server_Host;

                smtp.EnableSsl = true;

                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

                NetworkCred.UserName = Networked_Username;

                NetworkCred.Password = Gmail_Password;

                smtp.UseDefaultCredentials = true;

                smtp.Credentials = NetworkCred;

                smtp.Port = Gmailport;

                smtp.Send(mm);
            }
            catch (System.Net.Mail.SmtpException)
            {
                throw;
            }
        }

        public int RecoverCredentials(RegistrationModel RegistrationModel)
        {
            HeRegistryDatalayer.IeCashDatalayerClient DataLayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            int Results = 0;

            try
            {
                RegistrationModel Credentials = new RegistrationModel();

                Credentials = DataLayer.RecoverCredentials(RegistrationModel);

                if (Credentials.sUsername != null && Credentials.sPassword != null)
                {
                    SendEmail(Credentials.sUsername, Credentials.sPassword, Credentials.sEmail, "You have requsted for your credentials. Please find your credentials below.", "Ecash Credentials Recovery");

                    Results = 1;
                }
                else
                {
                    Results = 0;
                }
            }
            catch (Exception)
            {

                Results = 2;
            }
            return Results;
        }

        private String BuildBody(String ClientName, String GUID)
        {
            StringBuilder Str = new StringBuilder();

            Str.Append("Dear  " + ClientName + "<br><br>");

            Str.Append("Please Click the Following Link to verify your registration on the Following Link " + "<br><br>");

            Str.Append(ConfigurationManager.AppSettings.Get("RegistrationURL") + GUID);

            Str.Append("<br><br>");

            Str.Append("Kind Regards" + "<br><br><br>");

            Str.Append("Ecash Team" + "<br>");

            return Str.ToString();
        }

        private String BuildBody_Recover(String sClientName, String sPassword, String sMessage)
        {
            StringBuilder Str = new StringBuilder();

            Str.Append("Dear  " + sClientName + "<br><br>");

            Str.Append(sMessage + "<br><br>");

            Str.Append("Username:" + sClientName);

            Str.Append("<br><br>");

            Str.Append("Password:" + sPassword);

            Str.Append("<br><br>");

            Str.Append("Kind Regards" + "<br><br><br>");

            Str.Append("Ecash Team" + "<br>");

            return Str.ToString();
        }

        #endregion
        #region Ministries

        public  IList<MinistryModel> GetMinistries()
        {

            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

           return datalayer.GetMinistries();

        }

        #endregion

        #region Atcs And Bills

        public String AddActsBills(ActsAndBillsModel Actsandbills)
        {
            String Results = null;
            
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            Results = datalayer.AddActsBills(Actsandbills);

            return Results;
        }


         public String UpdatedActsBills(ActsAndBillsModel Actsandbills)
        {
            String Results = null;
            
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             Results = datalayer.UpdatedActsBills(Actsandbills);
             return Results;

        }
         public IList<ActsAndBillsModel> GetActsbills(ActsAndBillsModel Actsandbills)
         {
             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             return datalayer.GetActsbills(Actsandbills);

         }


         public String DeleteActsBills(int iActsAndBillID)
         {
             String Results = null;
            
             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            Results  =  datalayer.DeleteActsBills(iActsAndBillID);

            return Results;

         }
        #endregion

        #region Bringupfiles
           

         public IList<BringupFilesModel> GetBringupFiles()
         {

             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             return datalayer.GetBringupFiles();
         }
         
         public String UpdateBringupFiles(BringupFilesModel Model)
         {

             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             return datalayer.UpdateBringupFiles(Model);
         }


         public String AddBringupFiles(BringupFilesModel model)
         {
               HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

               return datalayer.AddBringupFiles(model);
         }


         public IList<BringupFilesModel> GetFilterBringupFiles(String sReference)
         {
             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             return datalayer.GetFilterBringupFiles(sReference);

         }

         public String DeleteBringupFiles(int iFilesID)
         {
             HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

             return datalayer.DeleteBringupFiles(iFilesID);
         }
         #endregion

        #region Cabinet Authorities
                 #region Incomming
                 public String AddCabinetAuthority(CabinetAuthoritiesModel Model)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.AddCabinetAuthority(Model);
                 }

                 public String DeleteIncommingCabinetAuthorities(int iIncomingCabinetID)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.DeleteIncommingCabinetAuthorities(iIncomingCabinetID);
                 }


                 public IList<CabinetAuthoritiesModel> GetCabinetAuthoritiesBill(String sTITLE, String sREFERENCENUMBER)
                 { 
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.GetCabinetAuthoritiesBill(sTITLE, sREFERENCENUMBER);
                 }

                 public String UpdateCabinetAuthority(CabinetAuthoritiesModel model) 
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.UpdateCabinetAuthority(model);
                 }

                #endregion 

                #region Dispatch 

                 public String AddDispatchcabinetauthority(DispatchCabinetAuthorityModel Model) 
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.AddDispatchcabinetauthority(Model);
                 }


                 public IList<DispatchCabinetAuthorityModel> GetDispatchcabinetauthority(String sREFERENCENUMBER, String sYear)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.GetDispatchcabinetauthority(sREFERENCENUMBER, sYear);
                 }

                 public String DeleteDispatchCabinetAuthorities(int CabinetauthorityID)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.DeleteDispatchCabinetAuthorities(CabinetauthorityID);
                 }


                 public String UpdateDispatchcabinetauthority(DispatchCabinetAuthorityModel Model)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.UpdateDispatchcabinetauthority(Model);

                 }
                #endregion


        #endregion

        #region Classifier

                 public String AddClassifier(ClassifierModel Model)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.AddClassifier(Model);
                 }
                 public String UpdateClassifier(ClassifierModel Model)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.UpdateClassifier(Model);
                 }

                 public String DeleteClassifier(ClassifierModel Model)
                 {
                     HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

                     return datalayer.DeleteClassifier(Model);
                 } 
        #endregion

        #region OutGoging Mail 
     
        public String DeleteOutgoingMail(OutGoingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteOutgoingMail(Model);
        }
        public String AddOutgoingMail(OutGoingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddOutgoingMail(Model);
        }
        public String UpdateOutgoingMail(OutGoingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateOutgoingMail(Model);
        }
        public IList<DeliveryModel> GetDeliverytype()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetDeliverytype();

        }

        public IList<SignatoriesModel> GetSignatories()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetSignatories();

        } 

        public IList<SectionDepartmentModel> GetSectionDepartment()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetSectionDepartment(); 
        }




        public IList<OutGoingmailModel> GetOutgoingmailbyDate(OutGoingmailModel model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetOutgoingmailbyDate(model);
        }

        public IList<OutGoingmailModel> GetOutgoingmailbyReferencenumber(OutGoingmailModel model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetOutgoingmailbyReferencenumber(model);
        }

     
        public IList<OutGoingmailModel> GetOutgoingmailbySubject(OutGoingmailModel model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetOutgoingmailbySubject(model);
        }
     
        #endregion
        
        #region Incomming Mail
        //search
        public IList<IncommingmailModel> GetIncommingMailbyDateofSubject(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetIncommingMailbyDateofSubject(Model);
        }

        public IList<IncommingmailModel> GetIncommingMailbyDateofReferencenumber(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetIncommingMailbyDateofReferencenumber(Model);
        }


        public IList<IncommingmailModel> GetIncommingMailbyDateofPrivateindivisual(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetIncommingMailbyDateofPrivateindivisual(Model);
        }

        public IList<IncommingmailModel> GetIncommingMailbyDateofReceipt(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetIncommingMailbyDateofReceipt(Model);
        }

        public IList<IncommingmailModel> GetIncommingMailbyMinistryname(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetIncommingMailbyMinistryname(Model);
        }
        //Crud
 
        public String DeleteIncommingMail(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteIncommingMail(Model);
        }


        public String AddIncommingMail(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddIncommingMail(Model);
        }


        public String UpdateIncommingMail(IncommingmailModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateIncommingMail(Model);
        }

        public IList<RecepientReceiverModel> GetRecepientReceiver()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetRecepientReceiver();
        }
        #endregion 

        #region Markout 

        public String DELETEMarkoutcard(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DELETEMarkoutcard(Model);
        }


        public String UpdateMarkoutcard(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateMarkoutcard(Model);
        }

        public String AddMarkoutcard(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddMarkoutcard(Model);
        }


        //Search 
        public IList<MarkoutModel> GetmarkoutbyTakenby(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetmarkoutbyTakenby(Model);
        }

        public IList<MarkoutModel> GetmarkoutbyDateTaken(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetmarkoutbyDateTaken(Model);
        }

        public IList<MarkoutModel> GetmarkoutbyFilenumber(MarkoutModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetmarkoutbyFilenumber(Model);
        } 
       
        #endregion

        #region Policy File


        public IList<PolicyFileModel> GetPolicybyReference(PolicyFileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetPolicybyReference(Model);
        }
        public IList<PolicyFileModel> GetPolicybyTitle(PolicyFileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetPolicybyTitle(Model);
        }
        public String DeletePolicyFile(PolicyFileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeletePolicyFile(Model);
        }
 

        public String UpdatePolicyFile(PolicyFileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdatePolicyFile(Model);
        }
        public String AddPolicyFile(PolicyFileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddPolicyFile(Model);
        } 
        #endregion 

        #region Memo
        public IList<MemoModel> GetMemobySubject(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetMemobySubject(Model);
        }
        public IList<MemoModel> GetMemobyReferencenumber(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetMemobyReferencenumber(Model);
        }

        public IList<MemoModel> GetMemobySectionDepartment(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetMemobySectionDepartment(Model);
        }


        public String DeleteMemo(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteMemo(Model);
        }

        public String UpdateMemo(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateMemo(Model);
        }
        public String AddMemo(MemoModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddMemo(Model);
        }
        #endregion

        #region File 



        public string UpdateFile(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateFile(Model);
        }

        public string DeleteFile(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteFile(Model);
        }

        public string AddFile(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddFile(Model);
        }
        //search 

        public IList<FileModel> GetFilebyEcnumber(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetFilebyEcnumber(Model);
        }

        public IList<FileModel> GetFilebyTITLE(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetFilebyTITLE(Model);
        }

        public IList<FileModel> GetFilebyReferencenumber(FileModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetFilebyReferencenumber(Model);
        }
        #endregion

        #region stations 
        public IList<StationsModel> GetStation()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetStation();
        }
        #endregion

        #region Post 
        public IList<PostModel> GetPostList()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetPostList();
        }
        public IList<PostModel> GetJobtitlecurrent()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetJobtitlecurrent();
        } 
        #endregion 

        #region Fileindex


        //IList<FileindexModel> GetFileindexbyReferencenumber(FileModel model);

        //[OperationContract]
        //IList<FileindexModel> GetFileindexbyTitle(FileModel model);
        public IList<FileindexModel> GetFileindexbyReferencenumber(FileindexModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetFileindexbyReferencenumber(Model);
        }


        public IList<FileindexModel> GetFileindexbyTitle(FileindexModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetFileindexbyTitle(Model);
        }

        public string DeleteFileindex(FileindexModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteFileindex(Model);
        }
        public string UpdateFileindex(FileindexModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateFileindex(Model);
        }
        public string AddFileindex(FileindexModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddFileindex(Model);
        }

        #endregion 

        #region Defence official
        public IList<DefenceMinutesModel> GetPurposeofApproval()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetPurposeofApproval();
        }
        public string UpateDefenceMinutes(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpateDefenceMinutes(Model);
        }
 
        public IList<DefenceMinutesModel> GetDefenceminutesnumber()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetDefenceminutesnumber();
        }

        public string DeleteDefenceMinutes(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteDefenceMinutes(Model);
        }

        public string AddDefenceMinutes(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddDefenceMinutes(Model);
        }

        public string AddDefenceofficials(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddDefenceofficials(Model);
        }

        public string UpdateDefenceofficials(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateDefenceofficials(Model);
        }

        public string DeleteDefenceofficials(DefenceMinutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteDefenceofficials(Model);
        }

        public string AddDefenceDispatch(DispatchMunutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.AddDefenceDispatch(Model);
        }


        public string UpdateDefenceDispatch(DispatchMunutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.UpdateDefenceDispatch(Model);
        }
         
        public string DeleteDefenceDispatch(DispatchMunutesModel Model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.DeleteDefenceDispatch(Model);
        }


        public IList<DispatchMunutesModel> GetDefenceMinutesDispatch(DispatchMunutesModel model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetDefenceMinutesDispatch(model);
             
        }
        public IList<DefenceMinutesModel> GetminutesOfficialsname(DefenceMinutesModel model)
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetminutesOfficialsname(model);

        }
     #endregion
 
        #region Title Status Model 

        public IList<TitleStatusModel> GetJobtitlestatus()
        {
            HeRegistryDatalayer.IeCashDatalayerClient datalayer = new HeRegistryDatalayer.IeCashDatalayerClient();

            return datalayer.GetJobtitlestatus();
        }
        #endregion

        public IList<SchoolModel> GetSchoolsDataExtedend(int Userid)
        {
            HeRegistryDatalayer.IeCashDatalayerClient objeCash = new IeCashDatalayerClient();
            IList<SchoolModel> m_lstSchools = new ObservableCollection<SchoolModel>();

            m_lstSchools = objeCash.GetSchoolsDataExtedend(Userid);
            objeCash = null;
            return m_lstSchools;

        }


    }
}